package demo.xlj.yuyi.studentapp.common;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import demo.xlj.yuyi.studentapp.R;
import demo.xlj.yuyi.studentapp.base.BaseRxActivity;
import demo.xlj.yuyi.studentapp.bean.NewBean;
import demo.xlj.yuyi.studentapp.utils.ActivityUtil;

/**
 * 团委要闻 界面
 */
public class YouthLeagueNewsActivity extends BaseRxActivity {

    @BindView(R.id.ImageView_back)
    ImageView mImageViewBack;
    @BindView(R.id.TextView_Title)
    TextView mTextViewTitle;
    @BindView(R.id.RecyclerView_Youth_League_News)
    RecyclerView mRecyclerViewYouthLeagueNews;



    private String time[] = {"2018-03-09"
            ,"2018-02-11"
            ,"2018-02-11"
            ,"2018-02-07"
            ,"2018-02-07"
            ,"2018-02-06"
            ,"2018-02-06"
            ,"2018-02-05"
            ,"2018-02-05"

    };

    private String title[]={"山东师大附中两项校本教研成果正式出版"
            ,"山东师大附中学生在“第九届陈省身杯数学奥林匹克”中获奖"
            ,"喜迎新年增春联，情暖校园送祝福"
            ,"山东师大附中胡雨辰同学被授予“创建全国文明"
            ,"山东师大附中学校领导走访慰问退休老教师"
            ,"百“口”争锋，以“理”为先"
            ,"山东师大附中国际部矩形高一和高二年级家委会"
            ,"奋斗，是青春的主旋律"
            ,"山东师大附中成立省内首个校园社团林"

    };

    private String name[] = {"9"
            ,"2"
            ,"1"
            ,"3"
            ,"4"
            ,"5"
            ,"6"
            ,"7"
            ,"8"

    };

    private List<NewBean> mList = new ArrayList<>();

    private BaseQuickAdapter<NewBean, BaseViewHolder> baseQuickAdapter;


    private Handler myHandler = new Handler(){

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 11){
                baseQuickAdapter.addData(mList);

            }
        }
    };


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_youth_league_news);
        ButterKnife.bind(this);
        mTextViewTitle.setText("附中要闻");
        initRecycler();
        initListener();

    }

    /**
     * 添加监听
     */
    private void initListener() {
        baseQuickAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                ActivityUtil.openActivityFromLeftToRightByResult(YouthLeagueNewsActivity.this,YouthLeagueNewsWebViewActivity.class,"w_name",mList.get(position).getName());
            }
        });
    }


    /**
     * 配置RecyclerView
     */
    private void initRecycler() {
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(YouthLeagueNewsActivity.this);
        mRecyclerViewYouthLeagueNews.setLayoutManager(layoutManager);
        baseQuickAdapter = new BaseQuickAdapter<NewBean, BaseViewHolder>(R.layout.recycler_new_item) {
            @Override
            protected void convert(BaseViewHolder helper, NewBean item) {
                helper.setText(R.id.TextView_RecyclerView_Title, item.getTitle());
                helper.setText(R.id.TextView_RecyclerView_Time, item.getTime());
            }
        };
        baseQuickAdapter.setEmptyView(R.layout.recycler_loading,mRecyclerViewYouthLeagueNews);
        mRecyclerViewYouthLeagueNews.setAdapter(baseQuickAdapter);

        NewBean newBean;
        for (int i = 0; i < name.length; i++) {
            newBean = new NewBean(name[i],title
            [i],time[i]);
            mList.add(newBean);
        }

        myHandler.sendEmptyMessageDelayed(11,2000);

    }

    @OnClick(R.id.ImageView_back)
    public void onViewClicked() {
        YouthLeagueNewsActivity.this.finish();
    }


}
